<!DOCTYPE HTML>
<%@page import="shop.vo.ProductBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="shop.vo.FavoriteBean"%>
<%@page import="shop.vo.UserBean"%>
<%@page import="shop.factory.DAOFactory"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/favorite.css" />
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<title>收藏夹</title>
</head>
<%
	String username = (String) session.getAttribute("user");
	UserBean user = new UserBean();
	user.setUser_name(username);
	int id = DAOFactory.getIUserDAOInstance().findId(user);
	FavoriteBean fav = new FavoriteBean();
	fav.setUser_id(id);
	int nowPage = 1;
	int pageSize = 10;
	String str = request.getParameter("to");
	if (str != null) {
		nowPage = Integer.parseInt(str);
	}
	int up = nowPage;
	int next = nowPage;
	int maxPage = 0;
	int count = DAOFactory.getIFavoriteDAOInstance().getCount(fav);
	if (count % pageSize == 0) {
		maxPage = count / pageSize;
	} else {
		maxPage = (count / pageSize) + 1;
	}
	if (next < maxPage) {
		next += 1;
	}
	if (up > 1) {
		up -= 1;
	}
	List<FavoriteBean> list = DAOFactory.getIFavoriteDAOInstance().list(fav, nowPage, pageSize);
	Iterator<FavoriteBean> it = list.iterator();
%>
<body>
	<nav class="navbar navbar-default" role="navigation">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#bs-example-navbar-collapse-1">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
		</div>
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
				<li class="active"><a href="../index.jsp">首页</a></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyOrder"> <img src="../images/order.png" /> 我的订单
				</a></li>
				<li></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyCart"> <img src="../images/car.png" /> 我的购物车
				</a></li>
				<li><a href="<%=request.getContextPath() %>/FavoriteServlet?action=MyFav"> <img src="../images/favorite.png" /> 我的收藏
				</a></li>
				<li><a href="<%=request.getContextPath() %>/AddressServlet?action=MyAddress"> <img src="../images/address.png" /> 我的地址簿
				</a></li>
			</ul>

			<ul class="nav navbar-nav navbar-right">
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=xinxi"><span id="huanying">欢迎光临，游客</span></a></li>
				<li><a href="../Login/login.jsp">登陆</a></li>
				<li><a href="../Login/regist.jsp">注册</a></li>
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=logout" class="active" onclick="return confirm('确认退出?')">退出</a></li>
			</ul>
		</div>
	</nav>
	<div class="container">
		<div class="col-md-12">
			<h2 class="tittle">我的收藏夹</h2>
			<div class="page-header"></div>
		</div>
		<div class="container">
			<table class="table">
				<caption>我的收藏夹</caption>
				<thead>
					<tr>
						<th>序号</th>
						<th>商品</th>
						<th>价格</th>
						<th>收藏时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<%
						while (it.hasNext()) {
							FavoriteBean fav1 = it.next();
							ProductBean product = fav1.getProduct();
					%>
					<tr>
						<td><%=fav1.getFav_id() %></td>
						<td><a href="<%=request.getContextPath()%>/ProductServlet?action=xiangqing&proId=<%=product.getPro_id()%>"><%=product.getPro_name() %></a></td>
						<td><%=product.getPrice() %></td>
						<td><%=fav1.getFav_time() %></td>
						<td><span id="delete"><a href="<%=request.getContextPath() %>/FavoriteServlet?action=deleteFav&favId=<%=fav1.getFav_id()%>" onclick="return confirm('是否删除？')">删除</a></span> <span id="#"><a
								href="<%=request.getContextPath()%>/ProductServlet?action=gou&proID=<%=product.getPro_id()%>">加入购物车</a></span></td>
					</tr>
					<%
						}
					%>
					<tr>
					<td colspan="12" align="center"><span class="style1"> <a
							href="userList.jsp?to=1">首页</a>&nbsp;|&nbsp; <a
							href="userList.jsp?to=<%=up%>">上一页</a>&nbsp;|&nbsp;<a
							href="userList.jsp?to=<%=next%>">下一页</a>&nbsp;|&nbsp; <a
							href="userList.jsp?to=<%=maxPage%>">尾页</a>
					</span> &nbsp;&nbsp;第&nbsp;<%=nowPage%>&nbsp;页/共&nbsp;<%=maxPage%>&nbsp;页</td>
				</tr>
				</tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
<%
	String str0 = (String)session.getAttribute("user");
	if (session.getAttribute("user") != null) {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，<%=str0%>";
<%
	} else {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，游客";
<%
	}
%>
</script>
</html>